<template>
  <div class="main">
    <div class="login">
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
        size="mini"
      >
        <el-form-item label="账号" prop="loginId">
          <el-input
            type="text"
            v-model="ruleForm.loginId"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="loginPwd">
          <el-input
            type="password"
            v-model="ruleForm.loginPwd"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        
  
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >登录</el-button
          >
          <el-button @click="resetForm('ruleForm')">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    // 验证密码的方法
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        callback();
      }
    };
    // 验证账号
    var validateId = (rule,value,callback)=>{
       if (value === "") {
        callback(new Error("请输入账号"));
      } else {
        callback();
      }
    } ;
    return {
      // 表单数据
      ruleForm: {
        loginId:"",
        loginPwd: "",
      },
      // 表单的验证数据
      rules: {
        // 验证密码
       loginPwd: [{ validator: validatePass, trigger: "blur" }],
       loginId: [{ validator: validateId, trigger: "blur" }],
    
      },
    };
  },
  methods: {
    // 表单的提交方法
    submitForm(formName) {
      // 判断表单数据是否验证成功
      this.$refs[formName].validate(async(valid) => {
        if (valid) {
          // 实现登录
          let res=await this.$get('/Admin/Login',this.ruleForm)
          console.log(res);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 表单重置方法
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
.main {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  .login {
    width: 600px;
    height: 250px;
    border: 1px solid #ccc;
  }
}
</style>